{smcl}
{com}{sf}{ul off}{txt}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\nkalmoe\Dropbox\Research\A Publishing\Finished\PSRM - VCM Partic\Kalmoe - Fig 2, Study 1.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}14 Jun 2017, 10:51:23

{com}. do "C:\Users\nkalmoe\Dropbox\Research\A Publishing\Finished\PSRM - VCM Partic\PSRM - Kalmoe Fig 2, Study 1.do"
{txt}
{com}. //PSRM - Kalmoe Figure 2, Study 1
. 
. ***Remember the order of variables is X, Z, W. ***
. ***On the graph, W represents the different lines.  ***
. 
. ***Nathan Note: This file attempts to combine parts of the 2- and 3-way ME plots from Golder. 
. ***The goal is to show the effect of violent metaphors on the change in partisan polarization on issues.
. ***Estimates 3-way model, subtracts difference between 2 lines, calculates SEs similar to 2-way model
. 
. * y = x z w xz xw zw xzw*
. * x(Treat), z(aggress), w(PID), y(dependent variable)
. 
. reg contrib viol aggress commitment violxaggress violxcommitment aggressxcommitment violxaggxcommit

      {txt}Source {c |}       SS       df       MS              Number of obs ={res}     502
{txt}{hline 13}{char +}{hline 30}           F(  7,   494) ={res}    9.33
    {txt}   Model {char |} {res} 4.17893048     7  .596990069           {txt}Prob > F      = {res} 0.0000
    {txt}Residual {char |} {res} 31.6119062   494  .063991713           {txt}R-squared     = {res} 0.1168
{txt}{hline 13}{char +}{hline 30}           Adj R-squared = {res} 0.1042
    {txt}   Total {char |} {res} 35.7908367   501  .071438796           {txt}Root MSE      = {res} .25297

{txt}{hline 19}{c TT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{col 1}           contrib{col 20}{c |}      Coef.{col 32}   Std. Err.{col 44}      t{col 52}   P>|t|{col 60}     [95% Con{col 73}f. Interval]
{hline 19}{c +}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{space 14}viol {c |}{col 20}{res}{space 2} .1388825{col 32}{space 2}  .105268{col 43}{space 1}    1.32{col 52}{space 3}0.188{col 60}{space 4}-.0679456{col 73}{space 3} .3457107
{txt}{space 11}aggress {c |}{col 20}{res}{space 2} .6053278{col 32}{space 2} .2132921{col 43}{space 1}    2.84{col 52}{space 3}0.005{col 60}{space 4} .1862563{col 73}{space 3} 1.024399
{txt}{space 8}commitment {c |}{col 20}{res}{space 2} .6904392{col 32}{space 2} .1221326{col 43}{space 1}    5.65{col 52}{space 3}0.000{col 60}{space 4} .4504759{col 73}{space 3} .9304026
{txt}{space 6}violxaggress {c |}{col 20}{res}{space 2}-.5828886{col 32}{space 2} .3127597{col 43}{space 1}   -1.86{col 52}{space 3}0.063{col 60}{space 4}-1.197392{col 73}{space 3} .0316148
{txt}{space 3}violxcommitment {c |}{col 20}{res}{space 2} -.321726{col 32}{space 2} .1791769{col 43}{space 1}   -1.80{col 52}{space 3}0.073{col 60}{space 4}-.6737689{col 73}{space 3} .0303169
{txt}aggressxcommitment {c |}{col 20}{res}{space 2}-1.284387{col 32}{space 2} .3991628{col 43}{space 1}   -3.22{col 52}{space 3}0.001{col 60}{space 4}-2.068653{col 73}{space 3}-.5001207
{txt}{space 3}violxaggxcommit {c |}{col 20}{res}{space 2} 1.363801{col 32}{space 2} .5599556{col 43}{space 1}    2.44{col 52}{space 3}0.015{col 60}{space 4} .2636129{col 73}{space 3}  2.46399
{txt}{space 13}_cons {c |}{col 20}{res}{space 2} -.118522{col 32}{space 2} .0708704{col 43}{space 1}   -1.67{col 52}{space 3}0.095{col 60}{space 4}-.2577666{col 73}{space 3} .0207225
{txt}{hline 19}{c BT}{hline 11}{hline 11}{hline 9}{hline 8}{hline 13}{hline 12}
{res}{txt}
{com}. 
. #delimit ;
{txt}delimiter now ;
{com}. *Estimating marginal effect of treatment, conditional on TA and PID*;
. egen zmin = min(aggress);
{txt}
{com}. egen zmax = max(aggress);
{txt}
{com}. gen z0 = (((_n-1)/(20-1))*(zmax-zmin))+zmin in 1/20;
{txt}(492 missing values generated)

{com}. generate Z=z0;
{txt}(492 missing values generated)

{com}. *     ****************************************************************  *;
. *       Generate the values of W for which you want to calculate the    *;
. *       marginal effect (and standard errors) of X on Y.                *;
. *     ****************************************************************  *;
. scalar W0=0;
{txt}
{com}. scalar W1=1;
{txt}
{com}. *     ****************************************************************  *;
. *       Grab elements of the coefficient and variance-covariance matrix *;
. *       that are required to calculate the marginal effect and standard *;
. *       errors.                                                         *;
. *     ****************************************************************  *;
. matrix b=e(b);
{txt}
{com}. matrix V=e(V);
{txt}
{com}. scalar b1=b[1,1];
{txt}
{com}. scalar b2=b[1,2];
{txt}
{com}. scalar b3=b[1,3];
{txt}
{com}. scalar b4=b[1,4];
{txt}
{com}. scalar b5=b[1,5];
{txt}
{com}. scalar b6=b[1,6];
{txt}
{com}. scalar b7=b[1,7];
{txt}
{com}. scalar varb1=V[1,1];
{txt}
{com}. scalar varb2=V[2,2];
{txt}
{com}. scalar varb3=V[3,3];
{txt}
{com}. scalar varb4=V[4,4];
{txt}
{com}. scalar varb5=V[5,5];
{txt}
{com}. scalar varb6=V[6,6];
{txt}
{com}. scalar varb7=V[7,7];
{txt}
{com}. scalar covb1b4=V[1,4];
{txt}
{com}. scalar covb1b5=V[1,5];
{txt}
{com}. scalar covb1b7=V[1,7];
{txt}
{com}. scalar covb4b5=V[4,5];
{txt}
{com}. scalar covb4b7=V[4,7];
{txt}
{com}. scalar covb5b7=V[5,7];
{txt}
{com}. scalar list b1 b2 b3 b4 b5 b6 b7 varb1 varb2 varb3 varb4 varb5 varb6 varb7 
>            covb1b4 covb1b5 covb1b7 covb4b5 covb4b7 covb5b7;
{txt}        b1 = {res} .13888254
{txt}        b2 = {res} .60532778
{txt}        b3 = {res} .69043922
{txt}        b4 = {res}-.58288857
{txt}        b5 = {res}-.32172597
{txt}        b6 = {res}-1.2843868
{txt}        b7 = {res} 1.3638013
{txt}     varb1 = {res} .01108135
{txt}     varb2 = {res}  .0454935
{txt}     varb3 = {res} .01491637
{txt}     varb4 = {res} .09781865
{txt}     varb5 = {res} .03210438
{txt}     varb6 = {res} .15933091
{txt}     varb7 = {res} .31355029
{txt}   covb1b4 = {res} -.0269231
{txt}   covb1b5 = {res}-.01751597
{txt}   covb1b7 = {res} .04325267
{txt}   covb4b5 = {res} .04325845
{txt}   covb4b7 = {res}-.16159613
{txt}   covb5b7 = {res}-.08105178
{txt}
{com}.            *     ****************************************************************  *;
. *       We want to calculate the marginal effect of X on Y for all      *;
. *       Z values of the modifying variable Z. We also want to          *;
. *       calculate this marginal effect as Z changes for specific values *;
. *       of the second modifying variable W.  In the code below, we      *;
. *       calculate the marginal effect of X on Y for all values of Z     *;
. *       when W=0, when W=1, when W=2, and when W=3.                     *;
. *     ****************************************************************  *;
. gen conb0=b1+b4*Z+b5*W0+b7*(Z*W0);
{txt}(492 missing values generated)

{com}. gen conb1=b1+b4*Z+b5*W1+b7*(Z*W1);
{txt}(492 missing values generated)

{com}. gen conbdif=conb1-conb0;
{txt}(492 missing values generated)

{com}. *     ****************************************************************  *;
. *       Calculate the standard errors for the marginal effect of X on Y *;
. *       for all Z values of the modifying variable Z. Do this for the  *;
. *       case when W=0, when W=1, when W=2, and when W=3.                *;
. *     ****************************************************************  *;
. gen conse0=sqrt(varb1
>                + varb4*(Z^2) + varb5*(W0^2) + varb7*(Z^2)*(W0^2)
>                + 2*Z*covb1b4 + 2*W0*covb1b5 + 2*Z*W0*covb1b7 + 2*Z*W0*covb4b5
>                + 2*W0*(Z^2)*covb4b7 + 2*(W0^2)*Z*covb5b7);
{txt}(492 missing values generated)

{com}. gen conse1=sqrt(varb1
>                + varb4*(Z^2) + varb5*(W1^2) + varb7*(Z^2)*(W1^2)
>                + 2*Z*covb1b4 + 2*W1*covb1b5 + 2*Z*W1*covb1b7 + 2*Z*W1*covb4b5
>                + 2*W1*(Z^2)*covb4b7 + 2*(W1^2)*Z*covb5b7);
{txt}(492 missing values generated)

{com}.                                                    gen consedif=sqrt(conse0^2 + conse1^2);
{txt}(492 missing values generated)

{com}.                                                                 gen a=1.645*consedif;
{txt}(492 missing values generated)

{com}.  gen upper=conbdif+a;
{txt}(492 missing values generated)

{com}.  gen lower=conbdif-a;
{txt}(492 missing values generated)

{com}.                         graph twoway line conbdif   Z, clwidth(medium) clcolor(blue) clcolor(black)
>         ||   line upper  Z, clpattern(dash) clwidth(thin) clcolor(black)
>         ||   line lower  Z, clpattern(dash) clwidth(thin) clcolor(black)
>         ||   ,   
>                  xlabel(0(.2)1, labsize(5)) 
>              ylabel(-1(.5)2, labsize(5))
>                  legend(off)
>              yline(0, lcolor(black))   
>              xtitle(Trait Aggression, size(5)  )
>              xsca(titlegap(2))
>              ysca(titlegap(2))
>              ytitle(Marginal Treatment FX on Impact of Motives, size(4))
>              scheme(s2mono) graphregion(fcolor(white));
{res}{txt}
{com}.              drop zmax zmin z0 Z conb0 conb1 conbdif conse0 conse1 consedif a upper lower;
{txt}
{com}. 
{txt}end of do-file

{com}. log close
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\nkalmoe\Dropbox\Research\A Publishing\Finished\PSRM - VCM Partic\Kalmoe - Fig 2, Study 1.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res}14 Jun 2017, 10:51:36
{txt}{.-}
{smcl}
{txt}{sf}{ul off}